In this lesson, you learned about the fundamentals of the Visual C++ compiler and how to enter and edit programs using Visual C++'s workbench. You saw the following:
This project reviews entering and editing a Visual C++ program using the workbench. You are not expected to understand how the program works. The format of future projects will concentrate much more on Visual C++'s language specifics using a different project format.
Step 1: Start Visual C++.
Before using Visual C++, you must start the workbench. Follow these steps:
Step 2: Open a program window.
Although I describe keystrokes to issue the commands, feel free to use the mouse to select menu options. Neither is a better way to use Windows; just use the way that is easiest for you.
Project 1 Listing. The Visual C++ project program.
// Filename: PROJECT1.CPP
// Prints the first 20 odd, then even, numbers.
// Once done, it prints them in reverse order.
#include <iostream.h>
void main()
{
int num; // The for loop control variable
cout << "The first 20 odd numbers:\n";
for (num = 1; num < 40; num += 2)
{ cout << num << ' '; }
cout << "\n\nThe first 20 even numbers:\n";
for (num = 2; num <= 40; num += 2)
{ cout << num << ' '; }
cout << "\n\nThe first 20 odd numbers in reverse:\n";
for (num = 39; num >= 1; num -= 2)
{ cout << num << ' '; }
cout << "\n\nThe first 20 even numbers in reverse:\n";
for (num = 40; num >= 2; num -= 2)
{ cout << num << ' '; }
return;
}
Step 3: Compile and run the program.
The first 20 odd numbers: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 The first 20 even numbers: 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 The first 20 odd numbers in reverse: 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 The first 20 even numbers in reverse: 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2
Step 4: Save your work.
If you exit Visual C++ without saving your program, you'll lose the program and have to reenter it in order to see the results again. Therefore, you'll want to save your programs to a disk file.
All of the programs in this book, including the one shown in Listing 1, are stored on the enclosed program disk. You don't have to save this listing unless you want the practice, because it is already on the disk.
Step 5: Exit Visual C++.